<template>
  <div class="login-page">
    <div class="login-main login-bg" style="min-height:100vh; display:flex; align-items:center; justify-content:center; position: relative;">
      <div class="login-overlay"></div>
      <div class="login-container" style="max-width:520px; width: 100%; position: relative; z-index: 1;">
        <div class="brand text-center mb-6" style="text-align:center; margin-bottom: 24px;">
          <div class="brand-row"> 
            <img class="brand-icon" style="max-width:44px" :src="require('@/assets/logo.png')" alt="logo" />
            <div class="app-title">询标系统</div>
          </div>
        </div>
        <el-card class="login-card glass-card">
          <div slot="header" class="headline font-weight-medium" style="text-align:center; font-size:20px;">登录用户账号</div>
          <div style="padding: 16px;">
            <el-form ref="form" label-position="top">
              <el-form-item label="账号">
                <el-input v-model="loginId" placeholder="请输入账号"></el-input>
              </el-form-item>
              <el-form-item label="密码">
                <el-input v-model="password" :type="showPwd ? 'text':'password'" placeholder="请输入密码"></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div class="px-6 pb-6" style="padding: 0 24px 24px 24px;">
            <el-button :loading="loading" type="primary" class="login-btn" style="width:100%" @click="handleLogin">登录</el-button>
          </div>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script>
import { login as apiLogin } from '@/api/user'

export default {
  name: 'Login',
  data () {
    return {
      loginId: '',
      password: '',
      role: 'expert',
      showPwd: false,
      loading: false,
      roles: [
        { title: '专家', value: 'expert' },
        { title: '投标人', value: 'bidder' },
        { title: '管理员', value: 'admin' }
      ]
    }
  },
  methods: {
    async handleLogin () {
      console.log('开始登录，账号:', this.loginId)
      
      if (!this.loginId || !this.password) {
        alert('请输入账号和密码')
        return
      }
      
      this.loading = true
      try {
        console.log('调用登录接口...')
        const data = await apiLogin(this.loginId, this.password)
        if(data.IsSuccess!=true){
          alert('登录失败，请检查您的用户名和密码是否正确。');
          this.$router.push('/login');
        }else{

          this.$router.push('/admin/dashboard');
        }
          
        
       
      } catch (e) {
        console.error('登录错误:', e)
        const errorMsg = e?.message || e?.data?.Msg || e || '登录失败'
        alert(`登录失败: ${errorMsg}`)
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>
.login-bg {
  background-image: url('../assets/login.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.login-main { position: relative; }
.login-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, rgba(0, 102, 255, 0.55), rgba(0, 180, 255, 0.45));
  pointer-events: none; /* 不阻挡交互 */
}
.login-main > .v-container { position: relative; z-index: 1; }
.brand-logo { filter: drop-shadow(0 6px 12px rgba(0,0,0,0.2)); }
.app-title {
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 2px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.brand-row {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.brand-icon {
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.2));
}
.login-card {
  border-radius: 12px;
  overflow: hidden;
}
.glass-card {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 12px 30px rgba(0, 87, 255, 0.18), 0 2px 8px rgba(0,0,0,0.06);
}

.login-btn {
  height: 44px;
  font-weight: 600;
  letter-spacing: 1px;
}

/* 关键修正：去掉 v-text-field 底色（Vuetify 2） */
.login-card >>> .v-text-field .v-input__slot,
.login-card ::v-deep .v-text-field .v-input__slot {
  background-color: transparent !important;
  box-shadow: none !important;
}

/* Outlined 边框颜色与交互态 */
.login-card >>> .v-text-field--outlined .v-input__slot,
.login-card ::v-deep .v-text-field--outlined .v-input__slot {
  border: 1px solid rgba(0, 0, 0, 0.25) !important;
}

.login-card >>> .v-input--is-focused.v-text-field--outlined .v-input__slot,
.login-card ::v-deep .v-input--is-focused.v-text-field--outlined .v-input__slot {
  border-color: #1976d2 !important;
  border-width: 2px !important;
}

/* 输入文字与占位符颜色微调 */
.login-card >>> .v-text-field input,
.login-card ::v-deep .v-text-field input {
  color: rgba(0,0,0,0.85);
}
.login-card >>> .v-text-field input::placeholder,
.login-card ::v-deep .v-text-field input::placeholder {
  color: rgba(0,0,0,0.45);
  opacity: 1;
}

@media (max-width: 600px) {
  .app-title { font-size: 24px; }
  .brand-logo { max-width: 60px !important; }
}
</style>
